home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / devices and hardware / disks / iso9660 / mydialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.1 KB  |  229 lines

  1. /*
  2.     File:        mydialog.c
  3.     
  4.     Description:
  5.  
  6.     Author:        
  7.  
  8.     Copyright:     Copyright: © 1990-1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.                 6/24/99    Updated for Metrowerks Codewarror Pro 2.1(KG)
  21.  
  22. */
  23.  
  24. #include <stdio.h>
  25. #include <strings.h>
  26. #include <Dialogs.h>
  27. #include <Windows.h>
  28. #include <Fonts.h>
  29. #include <Files.h>
  30. #include <Resources.h>
  31. #include <Memory.h>
  32. #include <Sound.h>
  33.  
  34. #include "mydialog.h"
  35. #include "DialogUtils.h"
  36. #include "mydialog.h"
  37.  
  38. #define    VOLNAME_DIALOG        256
  39. #define    DESTROY_DIALOG        257
  40. #define FirstButton            1
  41. #define SecondButton        2
  42. #define StringField            3
  43.  
  44. static void strcpy255(char *dst, char *src);
  45.  
  46. extern void strcpy255(char *, char *);
  47.  
  48.  
  49. /************************************************************************
  50.  *
  51.  *  Function:        strcpy255
  52.  *
  53.  *  Purpose:        copy a string
  54.  *
  55.  *  Returns:        nothing
  56.  *
  57.  *  Side Effects:    copies *src into *dst
  58.  *
  59.  *  Description:    loop copying until we hit the null byte of src.
  60.  *                    We stop copying if we try to copy more than 255
  61.  *                    chars at a time.
  62.  *
  63.  ************************************************************************/
  64. static void
  65. strcpy255(char *dst, char *src)
  66. {
  67.     short i = 0;
  68.     while ( ( (*dst++ = *src++) != 0) & (i++ < 255) )
  69.         /* nothing */ ;
  70. }
  71.  
  72. /************************************************************************
  73.  *
  74.  *  Function:        AskForString
  75.  *
  76.  *  Purpose:        ask the user for a string.
  77.  *
  78.  *  Returns:        Boolean
  79.  *                        true if the user entered something
  80.  *                        false if the user asked to cancel out
  81.  *
  82.  *  Side Effects:
  83.  *                    theString is filled with a C string if we return true.
  84.  *
  85.  *  Description:
  86.  *                    put up a dialog.
  87.  *
  88.  ************************************************************************/
  89. Boolean
  90. AskForString(char *prompt, char *theString)
  91. {
  92.     DialogPtr        dPtr;
  93.     short            result;
  94.     
  95.     short            unusedType;    /* for hiliting okay button */
  96.     Handle            hItem;
  97.     Rect            dBox;
  98.     
  99.     Boolean            leaveYet;
  100.     
  101.     Str255            enteredString;
  102.  
  103.     dPtr = GetNewDialog(DU_CenterDLOG(VOLNAME_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
  104.     
  105.     //HighLightDefault(dPtr);                /* hilite OK button */
  106.     
  107.     SelectDialogItemText(dPtr, StringField, 0, 999); /* all of the string field selected */
  108.  
  109.     ParamText((StringPtr)prompt, NULL, NULL, NULL);
  110.     
  111.     leaveYet = false;
  112.     do
  113.     {
  114.         //HighLightDefault(dPtr);
  115.         ModalDialog(0, &result);
  116.         if (result == FirstButton) 
  117.             leaveYet = true;
  118.         if (result == SecondButton)
  119.         {
  120.             SysBeep(1);
  121.             leaveYet = true;
  122.             return false;
  123.         }
  124.     } while (leaveYet == false);
  125.     
  126.  
  127.     GetDialogItem(dPtr, StringField, &unusedType, &hItem, &dBox);
  128.     GetDialogItemText(hItem, (StringPtr)&enteredString);
  129.     strcpy255(theString, P2CStr((StringPtr)&enteredString));
  130.     DisposeDialog(dPtr);
  131.     return true;
  132. }
  133.  
  134. /************************************************************************
  135.  *
  136.  *  Function:        AskDestroyDisk
  137.  *
  138.  *  Purpose:        Check that you really want to nuke a disk
  139.  *
  140.  *  Returns:        Boolean
  141.  *                    true = yes, destroy it
  142.  *                    false = no, leave it alone, it was a mistake.
  143.  *
  144.  *  Side Effects:    none.
  145.  *
  146.  *  Description:    display our warning about destroying a disk.
  147.  *                    Ask, using a modal dialog, whether the user really
  148.  *                    wants to lose it.  (Default button is cancel, since
  149.  *                    this is such a permanent thing...)
  150.  *
  151.  *
  152.  ************************************************************************/
  153. Boolean
  154. AskDestroyDisk(short gDriveNumber)
  155. {
  156.     DialogPtr        dPtr;
  157.     short            result;
  158.     Boolean            leaveYet;
  159.     Boolean            okayToDestroy;
  160.     
  161.     Str255            volumeName;
  162.     short            vRefNum;
  163.     long            freeBytes;
  164.  
  165.     okayToDestroy = true;
  166.     dPtr = GetNewDialog(DU_CenterDLOG(DESTROY_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
  167.  
  168.     //HighLightDefault(dPtr);
  169.     
  170.     if (GetVInfo(gDriveNumber, volumeName, &vRefNum, &freeBytes) != noErr)
  171.         okayToDestroy = false;
  172.     
  173.     if (okayToDestroy)
  174.     {
  175.         ParamText((StringPtr)volumeName, NULL, NULL, NULL);
  176.         
  177.         leaveYet = false;
  178.         do
  179.         {
  180.             //HighLightDefault(dPtr);
  181.             ModalDialog(0, &result);
  182.             if (result == SecondButton) 
  183.                 leaveYet = true;
  184.             if (result == FirstButton)
  185.             {
  186.                 SysBeep(1);
  187.                 leaveYet = true;
  188.                 okayToDestroy = false;
  189.             }
  190.         } while (leaveYet == false);
  191.     }
  192.  
  193.     DisposeDialog(dPtr);
  194.     return okayToDestroy;
  195. }
  196.  
  197.  
  198.  
  199. /************************************************************************
  200.  *
  201.  *  Function:        Help
  202.  *
  203.  *  Purpose:        explain what we're doing
  204.  *
  205.  *  Returns:        void
  206.  *
  207.  *  Side Effects:    none.
  208.  *
  209.  *  Description:    display our help text.  Currently always returns true.
  210.  *
  211.  *
  212.  ************************************************************************/
  213. Boolean
  214. Help(void)
  215. {
  216.     Handle    tHandle;
  217.         
  218.     tHandle = GetResource('TEXT', 1001);
  219.     if (tHandle != (Handle)0)
  220.     {
  221.         HLock(tHandle);
  222.         //TextDialog(1001, tHandle, times, 12, true);
  223.         HUnlock(tHandle);
  224.         ReleaseResource(tHandle);
  225.     }
  226.     return true;
  227. }
  228.  
  229.